package com.ktjy.web.dao.impl;

import com.ktjy.web.dao.AttrItemDao;
import com.ktjy.web.dao.AttrValuesDao;
import com.ktjy.web.dao.BaseDao;
import com.ktjy.web.entity.AttrItem;
import com.ktjy.web.entity.AttrValues;
import com.ktjy.web.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 规格属性DAO接口实现类
 * @version v1.0
 * @Author 郴州科泰
 * @Create 2024-07-24 - 21:06
 */
public class AttrItemDaoImpl extends BaseDao implements AttrItemDao {

    /**
     * 查询所有的规格属性
     */
    @Override
    public List<AttrItem> findAllAttr() {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<AttrItem> list=null;
        try{
            list=sqlSession.getMapper(AttrItemDao.class).findAllAttr();

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }

    /**
     * 根据商品id查询该商品的所有属性列表
     * @param goodsId 属性id
     * @return 返回该商品的所有属性列表
     */
    @Override
    public List<AttrItem> findAttrByGoodsId(int goodsId) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<AttrItem> list=null;
        try{
            list=sqlSession.getMapper(AttrItemDao.class).findAttrByGoodsId(goodsId);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }

    /**
     * 根据库存sku查询该sku的所有属性列表
     * @param stockSku 库存sku
     * @return 返回该商品的所有属性列表
     */
    @Override
    public List<AttrItem> findAttrByStockSku(String stockSku) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<AttrItem> list=null;
        try{
            list=sqlSession.getMapper(AttrItemDao.class).findAttrByStockSku(stockSku);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }

    @Override
    public List<AttrItem> selelctAll() {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<AttrItem> list=null;
        try{
            list=sqlSession.getMapper(AttrItemDao.class).selelctAll();

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }
}
